<template>
  <div>
    <el-dialog :visible.sync="dialogFormVisible" title="添加章节">
      <el-form>
        <el-form-item :label-width="formLabelWidth" label="章节标题">
          <el-input v-model="chapter.title" />
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="章节排序">
          <el-input-number v-model="chapter.sort" :min="0"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveChapter">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import chapterApi from '@/api/chapter'
export default {
  data() {
    return {
      chapter: {},
      form: {},
      formLabelWidth: '80px',
      dialogFormVisible: false
    }
  },
  methods: {
    saveChapter() {
      this.chapter.courseId = this.$parent.$parent.courseId
      // console.log(this.$parent)
      // console.log(this.$parent.$parent)
      // console.log(this.chapter)
      chapterApi.save(this.chapter).then(r => {
        this.$message.success('新增章节成功')
        this.dialogFormVisible = false
      })
    }
  }
}
</script>
